Golang : Split string
Problem :
Need to split this string ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES by comma
Solution :
Use the strings.Split function to split the string
package main
import (
"fmt"
"strings"
)
func main() {
str := "ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES"
strarray := strings.Split(str, ",")
fmt.Println(strarray)
}
Output :
[ADAM EVE CALEB SCOTT GRANTT JAMES]
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.8k Android Studio : Image button and button example
+14.9k Golang : How to check for empty array string or string?
+9.4k Golang : Create unique title slugs example
+4.5k Java : Generate multiplication table example
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+18.6k Golang : Find IP address from string
+14.5k Golang : Rename directory
+31.1k Golang : Calculate percentage change of two values
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+6.3k Golang : Extract sub-strings
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+15.6k Golang : Force download file example